package track2.result;



import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;

import track2.context.Config;

public class ResultFileTool {
	
	static AmazonS3 s3;
	
	public static void outputResult(Result result) throws IOException{
		AWSCredentials credentials = new PropertiesCredentials(
				ResultFileTool.class.getResourceAsStream("AwsCredentials.properties"));
		s3 = new AmazonS3Client(credentials);
		NumberFormat formatter = new DecimalFormat("#0.0000000000");
		try{
			File file = new File("output");      
			Writer bw = new OutputStreamWriter(new FileOutputStream(file));
			for (int i = 0; i < result.naiveBayesResultScore.length; i++){
				bw.write(formatter.format(result.naiveBayesResultScore[i]));
				bw.write("\n");
			}
			bw.flush();
			bw.close();
			s3.putObject("bigmlplj", "track2/result_NaiveBayes.txt",file);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
